#测试系统通知页面
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from common.Utils import CloudDriver
from selenium.webdriver.support import expected_conditions as EC


class Notify:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://vnollx.cloud/homepage"
        self.driver = CloudDriver.driver
        self.driver.get(self.url)

    def Message(self):
        self.driver.find_element(By.CSS_SELECTOR,"#notificationlink").click()
        # 切换
        iframe = self.driver.find_element(By.TAG_NAME, "iframe")
        self.driver.switch_to.frame(iframe)
        word=self.driver.find_element(By.CSS_SELECTOR,"#notifications-container > div > p").text
        print(word)
        assert word=="暂时没有新的系统通知"
        #退出之前，删除之前创建的文件和文件夹，根据名称直接查找
        self.driver.switch_to.default_content()
        self.driver.find_element(By.CSS_SELECTOR, "#allfilelink").click()
        # 切换
        iframe = self.driver.find_element(By.TAG_NAME, "iframe")
        self.driver.switch_to.frame(iframe)
        # 定位元素，右击选择
        elem = self.driver.find_element(By.CSS_SELECTOR, "#file-list > tr:nth-child(1) > td:nth-child(1)")
        # 定位
        EC.presence_of_element_located(elem)
        # 创建动作链对象
        actions = ActionChains(self.driver)
        # 右键点击元素
        actions.context_click(elem).perform()
        self.driver.find_element(By.CSS_SELECTOR,"#contextMenu > div:nth-child(2)").click()
        assert self.driver.find_element(By.CSS_SELECTOR,"#swal2-title").text=="确认要删除该文件夹吗？"
        self.driver.find_element(By.CSS_SELECTOR,"body > div.swal2-container.swal2-center.swal2-backdrop-show > div > div.swal2-actions > button.swal2-confirm.swal2-styled").click()

        # 定位元素，右击选择
        elem = self.driver.find_element(By.CSS_SELECTOR, "#file-list > tr:nth-child(1) > td:nth-child(1)")
        # 定位
        EC.presence_of_element_located(elem)
        # 创建动作链对象
        actions = ActionChains(self.driver)
        # 右键点击元素
        actions.context_click(elem).perform()
        self.driver.find_element(By.CSS_SELECTOR, "#contextMenu > div:nth-child(2)").click()
        assert self.driver.find_element(By.CSS_SELECTOR, "#swal2-title").text == "确认要删除该文件吗？"
        self.driver.find_element(By.CSS_SELECTOR,"body > div.swal2-container.swal2-center.swal2-backdrop-show > div > div.swal2-actions > button.swal2-confirm.swal2-styled").click()
        print("删除成功……")
        #切换
        self.driver.switch_to.default_content()
        # 然后点击退出登录按钮
        self.driver.find_element(By.CSS_SELECTOR, "#exit").click()
        print("所有页面测试完成，返回登录页面……")